<!DOCTYPE html>












  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
























<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2">

<link rel="stylesheet" href="/css/main.css?v=7.1.1">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.1.1">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.1.1">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.1.1">


  <link rel="mask-icon" href="/images/logo.svg?v=7.1.1" color="#222">







<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '7.1.1',
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false,"dimmer":false},
    back2top: true,
    back2top_sidebar: false,
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="keywords" content="框架-FastDFS文件服务">
<meta property="og:type" content="article">
<meta property="og:title" content="FastDFS单机搭建">
<meta property="og:url" content="http://SpiritPoet.github.io/2019/06/05/FastDFS单机搭建/index.html">
<meta property="og:site_name" content="超级码栗的博客">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://spiritpoet.github.io/2019/06/05/FastDFS单机搭建/1.png">
<meta property="og:image" content="http://spiritpoet.github.io/2019/06/05/FastDFS单机搭建/2.jpg">
<meta property="og:updated_time" content="2019-06-05T09:08:13.187Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="FastDFS单机搭建">
<meta name="twitter:image" content="http://spiritpoet.github.io/2019/06/05/FastDFS单机搭建/1.png">





  
  
  <link rel="canonical" href="http://SpiritPoet.github.io/2019/06/05/FastDFS单机搭建/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>FastDFS单机搭建 | 超级码栗的博客</title>
  












  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">超级码栗的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <p class="site-subtitle">上士闻道，勤而行之</p>
      
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="Toggle navigation bar">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
    
      
    

    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>Home</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">

    
    
    
      
    

    

    <a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>Tags</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">

    
    
    
      
    

    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>Categories</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
    
      
    

    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>Archives</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-about">

    
    
    
      
    

    

    <a href="/about/" rel="section"><i class="menu-item-icon fa fa-fw fa-user"></i> <br>About</a>

  </li>

      
      
    </ul>
  

  

  
</nav>



  



</div>
    </header>

    
  
  

  

  <a href="https://github.com/SpiritPoet" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewbox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></a>



    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://SpiritPoet.github.io/2019/06/05/FastDFS单机搭建/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="码栗">
      <meta itemprop="description" content="一位码栗的技术分享，计算机基础，计算机专业知识，java编程">
      <meta itemprop="image" content="/images/avatar/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="超级码栗的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">FastDFS单机搭建

              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              

              
                
              

              <time title="Created: 2019-06-05 11:01:27 / Modified: 17:08:13" itemprop="dateCreated datePublished" datetime="2019-06-05T11:01:27+08:00">2019-06-05</time>
            

            
              

              
            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/那些年追过的框架/" itemprop="url" rel="index"><span itemprop="name">那些年追过的框架</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><img src="/2019/06/05/FastDFS单机搭建/1.png" alt="架构图"></p>
<a id="more"></a>

<h1 id="FastDFS-单机版搭建"><a href="#FastDFS-单机版搭建" class="headerlink" title="FastDFS 单机版搭建"></a>FastDFS 单机版搭建</h1><h4 id="目标"><a href="#目标" class="headerlink" title="目标"></a>目标</h4><p>​ 搭建可使用的单服务器版 FastDFS 文件服务器,本文对原理不做阐述，因为作者也没有对 FastDFS 深入研究。如果后续深入研究作者一定再发文更新。</p>
<h4 id="简单概念介绍"><a href="#简单概念介绍" class="headerlink" title="简单概念介绍"></a>简单概念介绍</h4><p>Tracker 服务</p>
<p>跟踪服务器，主要负责调度 storage 节点与 client 通信，在访问上起负载均衡的作用，和记录 storage 节点的运行状态，是连接 client 和 storage 节点的枢纽</p>
<p>Storage 服务</p>
<p>存储服务器，保存文件和文件的 meta data（元数据）；</p>
<p>Group</p>
<p>文件组，也称为卷。做集群时一组会有多台服务器，同组服务器上的文件是完全相同的，当文件上传到组内的一台机器后，该文件会同步到同组内的其它所有机器上，起到备份的作用；</p>
<p>meta data</p>
<p>文件相关属性，键值对（KeyValue Pair）方式，如：width=1024, height=768；</p>
<h4 id="环境准备"><a href="#环境准备" class="headerlink" title="环境准备"></a>环境准备</h4><p>​ 1.操作系统 Centos 6.4</p>
<p>​ 2.包管理工具 yum (阿里源)</p>
<p>​ 3.依赖安装</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum -y install perl</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum -y install libevent</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install gcc-c++</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install -y unzip zip</span><br></pre></td></tr></table></figure>

<h4 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h4><p>​ 1.下载相关程序包</p>
<p>​ <a href="https://github.com/happyfish100" target="_blank" rel="noopener">FastDFS 官方 github 下载地址</a>，注意：要保持版本一致否则会有各种问题。这里我都是下载的 master 版本</p>
<p>fastdfs-master、 libfastcommon-master、fastdfs-nginx-module-master</p>
<p>​ 2.解压编译安装</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span>首先安装fast公共依赖包</span><br><span class="line">unzip -o libfastcommon-master.zip -d /usr/local</span><br><span class="line">cd /usr/local/libfastcommon-master</span><br><span class="line">./make.sh</span><br><span class="line">./make.sh install</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span>公共依赖包安装完，安装主程序包</span><br><span class="line">unzip -o fastdfs-master.zip -d /usr/local</span><br><span class="line">cd /usr/local/fastdfs-master</span><br><span class="line">./make.sh</span><br><span class="line">./make.sh install</span><br><span class="line">cp -r conf/* /etc/fdfs</span><br></pre></td></tr></table></figure>

<p>​ 安装完 libfastcommon-master 和 fastdfs-master 两个程序包，FastDFS 就已经安装完毕了。</p>
<h4 id="配置启动"><a href="#配置启动" class="headerlink" title="配置启动"></a>配置启动</h4><p>​ 1.配置启动 trackerd</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">cd /etc/fdfs/</span><br><span class="line">vi tracker.conf</span><br><span class="line"><span class="meta">#</span>常用配置项</span><br><span class="line">port=22122 #tracker程序的管理端口</span><br><span class="line">base_path=/home/fdfs/work/trackerd #存放tracker程序的 日志和一些数据的文件路径</span><br><span class="line">http.server_port=9999 #http访问tracker程序的端口</span><br><span class="line"><span class="meta">#</span>启动</span><br><span class="line">/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf</span><br><span class="line"><span class="meta">#</span>验证是否启动</span><br><span class="line">ps -ef | grep tracker</span><br></pre></td></tr></table></figure>

<p>​ 2.配置启动 storaged</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">cd /etc/fdfs/</span><br><span class="line">vim storage.conf</span><br><span class="line"><span class="meta">#</span>常用配置项</span><br><span class="line">port=23000 #storage程序的管理端口</span><br><span class="line">base_path=/home/fdfs/work/storage  #存放文件和日志的文件路径</span><br><span class="line">tracker_server=本地IP:22122 #指定tracker服务</span><br><span class="line">store_path0=/home/fdfs/work/storage #多仓库配置的时候设置多个(我们单机采用默认的和base_path相同)</span><br><span class="line">http.server_port=9998 #http访问tracker程序的端口</span><br><span class="line"><span class="meta">#</span>启动</span><br><span class="line">/usr/bin/fdfs_trackerd /etc/fdfs/storage.conf</span><br><span class="line"><span class="meta">#</span>验证是否启动</span><br><span class="line">ps -ef | grep storage</span><br></pre></td></tr></table></figure>

<p>​ 3.验证是否可上传文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span>这个是查看FastDFS所有的可执行命令</span><br><span class="line">ll /usr/bin/fdfs*</span><br><span class="line"><span class="meta">#</span>验证之前需要修改client.conf配置文件</span><br><span class="line">vim /etc/fdfs/client.conf</span><br><span class="line"><span class="meta">#</span>常用配置</span><br><span class="line">base_path=/home/fdfs/work/client #存放数据及日志文件 (路径文件夹必须存在)</span><br><span class="line">tracker_server=本地IP:22122 #指定tracker服务 (必须修改)</span><br><span class="line">http.tracker_server_port=9995 #http访问tracker程序端口</span><br><span class="line"><span class="meta">#</span>利用 fdfs_test 命令验证，使用方式:/usr/bin/fdfs_test 客户端配置文件地址 upload 上传文件</span><br><span class="line">/usr/bin/fdfs_test /etc/fdfs/client.conf  upload /etc/fdfs/client.conf</span><br><span class="line"><span class="meta">#</span>不包error即成功 会返回很多信息  包括url 但是此时的url是没法访问下载的，我们需要集合nginx</span><br></pre></td></tr></table></figure>

<p>​ 上传成功截图</p>
<p>​ <img src="/2019/06/05/FastDFS单机搭建/2.jpg" alt="上传成功截图"></p>
<p>配置完以上两个文件 并成功启动和测试 基本上一个单机版的 FastDFS 就完成 80%了接下来我们需要配置 nginx 完成下载。</p>
<h4 id="配置-nginx-模块"><a href="#配置-nginx-模块" class="headerlink" title="配置 nginx 模块"></a>配置 nginx 模块</h4><p>​ 1.安装依赖</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span>依赖包下载安装</span><br><span class="line">yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel</span><br></pre></td></tr></table></figure>

<p>​ 2.解压 nginx 和 fast-nginx-module-master 程序包,下载 nginx 在这里不做阐述，去即<a href="http://nginx.org/en/download.html" target="_blank" rel="noopener">官网下载</a>即可。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"> #</span>解压nginx和fastdfs-nginx-module-master</span><br><span class="line"> tar -zxvf /nginx-1.14.2.tar.gz</span><br><span class="line"> unzip -o fastdfs-nginx-module-master.zip -d /usr/local</span><br><span class="line"><span class="meta"> #</span>将/usr/local/fastdfs-nginx-module-master/src/下的mod_fastdfs.conf 复制到/etc/fdfs/下</span><br><span class="line"> cp /usr/local/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs</span><br><span class="line"><span class="meta"> #</span>修改mod_fastdfs.conf</span><br><span class="line"> store_path0=/home/fdfs/work/storage  #仓储路径 最好和storage配置一样</span><br><span class="line"> storage_server_port=23000  #要和storage的port配置一样</span><br><span class="line"> tracker_server=本地IP:22122 #指定tracker服务</span><br><span class="line"> base_path=/home/fdfs/work/storage #存放日志文件和一些数据文件</span><br><span class="line"><span class="meta"> #</span>为nginx添加模块</span><br><span class="line"> ./configure --prefix=/usr/local/nginx/ --add-module=/usr/local/fastdfs-nginx-module-master/src/</span><br><span class="line"> make</span><br><span class="line"> make install #如果是第一次安装nginx  需要install  如果已经存在nginx  则不需要这一步</span><br><span class="line"><span class="meta"> #</span>配置nginx.conf</span><br><span class="line"> server &#123;</span><br><span class="line"> 		listen 监听端口;</span><br><span class="line"> 		server_name 本机IP;</span><br><span class="line"></span><br><span class="line"> 		location /group1/M00/&#123;</span><br><span class="line"> 			ngx_fastdfs_module;</span><br><span class="line"> 		&#125;</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span>启动Nginx (如果重启可以采用  平滑重启 -s reload的方式)</span><br></pre></td></tr></table></figure>

<p>​ 3.验证下载</p>
<p>​ 上传文件后运用本机 ip+nginx 监听端口+group_name+remote_filename 的方式</p>
<p>grop_name 和 remote_filename 就是上面测试成功返回的信息中 画红线 的两个值</p>
<h4 id="结合-Java-Spring-Boot-框架-构建文件上传服务"><a href="#结合-Java-Spring-Boot-框架-构建文件上传服务" class="headerlink" title="结合 Java Spring Boot 框架 构建文件上传服务"></a>结合 Java Spring Boot 框架 构建文件上传服务</h4><p>这里我不做详细说明：提供一个别人的 github 项目给大家参考 <a href="https://github.com/bojiangzhou/lyyzoo-fastdfs-java" target="_blank" rel="noopener">请点击这里参考</a></p>
<h4 id="关于-FastDFS-下载文件名不是原来文件名的解决方案"><a href="#关于-FastDFS-下载文件名不是原来文件名的解决方案" class="headerlink" title="关于 FastDFS 下载文件名不是原来文件名的解决方案"></a>关于 FastDFS 下载文件名不是原来文件名的解决方案</h4><p>利用 nginx<br>修改 nginx.conf<br>在代理路径下添加如下代码</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> ($arg_attname ~ <span class="string">"^(.+)"</span>) &#123;</span><br><span class="line">    #设置下载</span><br><span class="line">    add_header Content-Type application/x-download;</span><br><span class="line">    #设置文件名</span><br><span class="line">    add_header Content-Disposition <span class="string">"attachment;filename=$arg_attname"</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<pre><code>完整配置如下</code></pre><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">location /group1/M00/ &#123;</span><br><span class="line">	root /fastdfs/data;  注释：填写数据存储路径，前面root别忘记</span><br><span class="line">	<span class="keyword">if</span> ($arg_attname ~ <span class="string">"^(.+)"</span>) &#123;</span><br><span class="line">    	#设置下载</span><br><span class="line">    	add_header Content-Type application/x-download;</span><br><span class="line">    	#设置文件名</span><br><span class="line">    	add_header Content-Disposition <span class="string">"attachment;filename=$arg_attname"</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	ngx_fastdfs_module;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>然后在请求后面跟上 ?arg_attname=文件名.后缀</p>
<p>例如：<br><a href="http://172.16.201.102:9800/gos/M00/00/04/wKgBalz2MJKEA8K5AAABAM3uJVE733.xls?arg_attname=测试.xls" target="_blank" rel="noopener">http://172.16.201.102:9800/gos/M00/00/04/wKgBalz2MJKEA8K5AAABAM3uJVE733.xls?arg_attname=测试.xls</a></p>

      
    </div>

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/框架-FastDFS文件服务/" rel="tag"># 框架-FastDFS文件服务</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/05/30/Hexo搭建博客/" rel="next" title="Hexo博客搭建">
                <i class="fa fa-chevron-left"></i> Hexo博客搭建
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/06/08/利用Vultr搭建Shadowsocks/" rel="prev" title="利用Vultr搭建Shadowsocks">
                利用Vultr搭建Shadowsocks <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  
    <div class="comments" id="gitalk-container">
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar/avatar.jpeg" alt="码栗">
            
              <p class="site-author-name" itemprop="name">码栗</p>
              <div class="site-description motion-element" itemprop="description">一位码栗的技术分享，计算机基础，计算机专业知识，java编程</div>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">3</span>
                    <span class="site-state-item-name">posts</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  
                    
                      <a href="/categories/">
                    
                  
                    
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">2</span>
                    <span class="site-state-item-name">categories</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  
                    
                      <a href="/tags/">
                    
                  
                    
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">3</span>
                    <span class="site-state-item-name">tags</span>
                  </a>
                </div>
              
            </nav>
          

          

          

          

          

          
          

          
            
          
          

        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#FastDFS-单机版搭建"><span class="nav-number">1.</span> <span class="nav-text">FastDFS 单机版搭建</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#目标"><span class="nav-number">1.0.0.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#简单概念介绍"><span class="nav-number">1.0.0.2.</span> <span class="nav-text">简单概念介绍</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#环境准备"><span class="nav-number">1.0.0.3.</span> <span class="nav-text">环境准备</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#安装"><span class="nav-number">1.0.0.4.</span> <span class="nav-text">安装</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#配置启动"><span class="nav-number">1.0.0.5.</span> <span class="nav-text">配置启动</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#配置-nginx-模块"><span class="nav-number">1.0.0.6.</span> <span class="nav-text">配置 nginx 模块</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#结合-Java-Spring-Boot-框架-构建文件上传服务"><span class="nav-number">1.0.0.7.</span> <span class="nav-text">结合 Java Spring Boot 框架 构建文件上传服务</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#关于-FastDFS-下载文件名不是原来文件名的解决方案"><span class="nav-number">1.0.0.8.</span> <span class="nav-text">关于 FastDFS 下载文件名不是原来文件名的解决方案</span></a></li></ol></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      

    </div>
  </aside>
  


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">码栗</span>

  

  
</div>









        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>














  
    
    
  
  <script color="0,0,255" opacity="0.5" zindex="-1" count="99" src="/lib/canvas-nest/canvas-nest.min.js"></script>













  
  <script src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>


  


  <script src="/js/utils.js?v=7.1.1"></script>

  <script src="/js/motion.js?v=7.1.1"></script>



  
  


  <script src="/js/affix.js?v=7.1.1"></script>

  <script src="/js/schemes/pisces.js?v=7.1.1"></script>



  
  <script src="/js/scrollspy.js?v=7.1.1"></script>
<script src="/js/post-details.js?v=7.1.1"></script>



  


  <script src="/js/next-boot.js?v=7.1.1"></script>


  

  

  

  


  
    

<script src="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>



<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.css">



<script src="//cdn.jsdelivr.net/npm/js-md5@0.7.3/src/md5.min.js"></script>

<script>
  var gitalk = new Gitalk({
    clientID: '239f5efbab16e8446c8b',
    clientSecret: '96d72b9243997bbdc6f08b7b37a70be47f5ccf0a',
    repo: 'SpiritPoet.github.io',
    owner: 'SpiritPoet',
    admin: ['SpiritPoet'],
    id: md5(location.pathname),
    
      language: 'zh-CN',
    
    distractionFreeMode: 'true'
  });
  gitalk.render('gitalk-container');
</script>

  


  




  

  

  
  

  
  

  


  

  

  

  

  

  

  

  

  

  

  

</body>
</html>
